package a1_3;

import java.util.ArrayList;
import java.util.List;

/**
 * 系部类，关联学院、教师和课程
 */
public class Department {
    private String deptId;
    private String deptName;

    // 关联：属于1个学院
    private School school;

    // 关联：至少有1个教师（List存储，控制数量≥1）
    private List<Instructor> instructors = new ArrayList<>();

    // 关联：至少提供1门课程（List存储，控制数量≥1）
    private List<Subject> providedSubjects = new ArrayList<>();

    public Department() {}

    public Department(String deptId, String deptName, School school) {
        this.deptId = deptId;
        this.deptName = deptName;
        this.school = school;
    }

    // 添加教师（至少1个）
    public void addInstructor(Instructor instructor) {
        instructors.add(instructor);
        instructor.setDepartment(this); // 双向关联，同步教师的系部
    }

    // 添加课程（至少1个）
    public void addProvidedSubject(Subject subject) {
        providedSubjects.add(subject);
    }

    // 校验约束：确保至少有1个教师和1门课程
    public boolean isValid() {
        return !instructors.isEmpty() && !providedSubjects.isEmpty();
    }

    // Getter/Setter
    public String getDeptId() {
        return deptId;
    }

    public void setDeptId(String deptId) {
        this.deptId = deptId;
    }

    public String getDeptName() {
        return deptName;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    public School getSchool() {
        return school;
    }

    public void setSchool(School school) {
        this.school = school;
    }

    public List<Instructor> getInstructors() {
        return new ArrayList<>(instructors);
    }

    public List<Subject> getProvidedSubjects() {
        return new ArrayList<>(providedSubjects);
    }
}
